import config from '@/config'

export default {
  setItem(key: string, val: any): void {
    let storage = this.getStorage()
    storage[key] = val
    window.localStorage.setItem(config.namespace, JSON.stringify(storage))
  },
  getItem(key: string): any {
    return this.getStorage()[key]
  },
  getStorage(): any {
    return JSON.parse(window.localStorage.getItem(config.namespace) || '{}')
  },
  removeItem(key: string): void {
    let storage = this.getStorage()
    delete storage[key]
    window.localStorage.setItem(config.namespace, JSON.stringify(storage))
  },
  clearAll(): void {
    window.localStorage.clear()
  }
}
